package com.tcode.springjpa.controller;

import com.tcode.springjpa.bean.Userbean;
import com.tcode.springjpa.services.UserServer;
import org.jboss.logging.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class JpaController {

    @Autowired
    private UserServer us;
    @GetMapping("queryUserPerson/{id}")
    public Userbean queryUserPerson(@PathVariable("id")int id){
        System.out.println("queryUserPerson");
        return us.findUserByID(id);
    }
    @GetMapping("queryAllUser")
    public List<Userbean> queryAllUser(){
        return us.findAllUser();
    }

    @GetMapping("modUser")
    public void modUser(){
        Userbean user=new Userbean();
        user.setUname("zhangxd");
        user.setPhone("13880788888");
        user.setUid(15);
        us.updateUser(user);
    }

    @GetMapping("addUser")
    public void addUser(){
        Userbean user=new Userbean();
        user.setUname("zhangxiaodong");
        user.setPhone("13880784687");
        us.insertUser(user);
    }
    @GetMapping("delUser/{id}")
    public void delUser(@PathVariable("id")int id){
        us.deletaUser(id);
    }
}
